 uint32_t count = 0;
uint16_t pwm = 0;

const int enPin = 6;
const int dirPin = 7;
const int pwmPin = 5;

void countPulse() {
  count++;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  // pin 2, RISING edge
  attachInterrupt(0, countPulse, RISING);
  
  // Enable and direction pins
  pinMode(enPin, OUTPUT);
  pinMode(dirPin, OUTPUT);  
  digitalWrite(enPin, HIGH);
  digitalWrite(dirPin, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("PWM: ");
  Serial.println(pwm);
  Serial.print("count: ");
  Serial.println(count);
  count = 0;
  analogWrite(5, pwm);
  pwm += 10;
  if (pwm > 255) {
    pwm = 0;
  }
  delay(1000);
}

// speed is 0 - 255
void rotateClockwise(uint8_t speed) {
  digitalWrite(dirPin, LOW);
  analogWrite(pwmPin, speed);
}

void rotateCounterClockwise(uint8_t speed) {
}

// speed is -255 to 255
void rotate(int speed) {
  if (speed > 0) {
    digitalWrite(dirPin, LOW);
    analogWrite(pwmPin, speed);
  } else {
    ???
  }
}

